import gql from 'graphql-tag';

/** 用户注册查看学校组织 */
export const USER_OrganList = gql`
  query getOrganList($type: NodeListType!) {
    nodeList(type: $type) {
      ... on Organ {
        id
        name
      }
    }
  }
`;

export const USER_SubjectList = gql`
  query getSubjectList($type: NodeListType!, $organ_id: ID!) {
    nodeList(type: $type, organ_id: $organ_id) {
      ... on Subject {
        id
        name
      }
    }
  }
`;

export const getUserInfo = gql`
  query getUserInfo {
    getSessionUser {
      ... on User {
        id
        name
        avatar_url
        phone
        childUserList {
          id
          name
        }
        parentUserList {
          id
          name
        }
        organs {
          id
          name
          subjects {
            id
            name
          }
          parentOrgan {
            id
            name
            parentOrgan {
              id
              name
            }
          }
        }
      }
    }
  }
`;

export const getUserInfoAdmin = gql`
  query getUserInfo {
    getSessionUser {
      ... on User {
        id
        name
        avatar_url
        organs {
          description
          location
          avatar_url
          childOrganList {
            id
            name
            childOrganList {
              id
              name
            }
          }
        }
      }
    }
  }
`;

/** 查看组织下的年级 */
export const getOrgan = gql`
  query getOrgan($id: ID!) {
    node(id: $id) {
      ... on Organ {
        id
        name
        childOrganList {
          id
          name
          childOrganList {
            id
            name
          }
        }
      }
    }
  }
`;

export const listSchoolAdminUsers = gql`
  query listSchoolAdminUsers(
    $type: NodeListType!
    $organ_id: ID!
    $role_id: ID
    $expand_organ_user: Boolean
    $name: String
  ) {
    nodeList(
      type: $type
      organ_id: $organ_id
      role_id: $role_id
      expand_organ_user: $expand_organ_user
      name: $name
    ) {
      ... on User {
        id
        name
        phone
        userRoles {
          is_host
        }
        childUserList {
          id
          name
        }
        organs {
          name
          id
          parentOrgan {
            id
            name
          }
        }
        roles {
          name
        }
      }
    }
  }
`;

export const getRoleList = gql`
  query getRoleList($type: NodeListType!) {
    nodeList(type: $type) {
      ... on Role {
        id
        name
      }
    }
  }
`;
